package cn.szsys.integration.ex;

import cn.szsys.integration.ex.enums.ExceptionEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 不要直接使用此异常类，应该使用其子类
 *
 * @author 50364
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class BaseException extends RuntimeException {
    protected String code;
    protected String reason;

    protected BaseException() {
        super();
    }

    protected BaseException(Throwable cause) {
        super(cause);
    }

    protected BaseException(ExceptionEnum ee, Throwable cause) {
        super(cause);
        this.reason = ee.getMsg();
        this.code = ee.getCode();
    }

    protected BaseException(ExceptionEnum ee, String reason) {
        super();
        this.reason = reason;
        this.code = ee.getCode();
    }

    protected BaseException(ExceptionEnum ee, Object... params) {
        super();
        this.reason = params != null && params.length > 0 ? String.format(ee.getMsg(), params) : ee.getMsg();
        this.code = ee.getCode();
    }

    protected BaseException(String ee, Throwable cause) {
        super(ee, cause);
        this.reason = ee;
        this.code = ExceptionEnum.OP_FAIL.getCode();
    }

    protected BaseException(String ee) {
        super(ee);
        this.reason = ee;
        this.code = ExceptionEnum.OP_FAIL.getCode();
    }

    protected BaseException(String code, String msg) {
        super();
        this.reason = msg;
        this.code = code;
    }
}
